/**    
 * @{#} RegisterActivity.java Create on 2014-5-26 下午9:51:05    
 *          
 * @author <a href="mailto:evan0502@qq.com">Evan</a>   
 * @version 1.0    
 */
package com.smiier.skin;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import cn.o.app.net.INetTask;
import cn.o.app.net.NetTaskListener;
import cn.skinapp.R;

import com.smiier.skin.constant.Constant;
import com.smiier.skin.net.UserGetTask;
import com.smiier.skin.net.UserGetTask.UserGetRequest;
import com.smiier.skin.net.UserGetTask.UserGetResponse;
import com.smiier.skin.net.UserSetTask;
import com.smiier.skin.net.UserSetTask.UserSetRequest;
import com.smiier.skin.net.UserSetTask.UserSetResponse;
import com.smiier.skin.ui.BasicActivity;
import com.smiier.skin.util.GlobalSettings;
import com.smiier.skin.utils.CommonUtility;
import com.umeng.analytics.MobclickAgent;

public class RegisterFourthStepActivity extends BasicActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_register_4);
		init();
		back.setVisibility(View.GONE);
		setNavTitle("注册成功");

	}

	public void onClick(View view) {
		int user_type = 0;
		int id = view.getId();
		if (id == R.id.rl_is_patinenter) {
			user_type = 1;
		} else if (id == R.id.rl_is_doctor) {
			user_type = 2;
		}
		UserSetRequest req = new UserSetRequest();
		// req.User_Type = user_type;
		req.token = GlobalSettings.sToken;
		UserSetTask task = new UserSetTask();
		task.setRequest(req);
		task.addListener(new NetTaskListener<UserSetTask.UserSetRequest, UserSetTask.UserSetResponse>() {

			@Override
			public void onException(
					INetTask<UserSetRequest, UserSetResponse> task, Exception e) {

			}

			@Override
			public void onComplete(
					INetTask<UserSetRequest, UserSetResponse> task,
					UserSetResponse response) {
				if (response.ResultCode != 200) {
					toast(R.string.server_unavailable);
					return;
				}
				UserGetRequest req = new UserGetRequest();
				req.uids = new ArrayList<Long>();
				req.uids.add(GlobalSettings.sUid);
				UserGetTask t = new UserGetTask();
				t.setRequest(req);
				t.addListener(new NetTaskListener<UserGetTask.UserGetRequest, UserGetTask.UserGetResponse>() {

					@Override
					public void onException(
							INetTask<UserGetRequest, UserGetResponse> task,
							Exception e) {

					}

					@Override
					public void onComplete(
							INetTask<UserGetRequest, UserGetResponse> task,
							UserGetResponse response) {
						if (response.ResultCode != 200) {
							return;
						}
						if (response.Res == null) {
							return;
						}
						if (response.Res.size() != 1) {
							return;
						}
						GlobalSettings.sUser = response.Res.get(0);
						int user_type = GlobalSettings.sUser.User_Type;
						if (user_type == 0) {
							startActivity(new Intent(getContext(),
									RegisterFourthStepActivity.class));
						} else {
							Intent intent = null;
							if (user_type == 1) {
								intent = new Intent(getContext(),
										PatientProfileEditActivity.class);
							} else if (user_type == 2) {
								intent = new Intent(getContext(),
										DoctorProfileEditActivity.class);
							}
							intent.putExtra(Constant.IDENTITY_KEY, true);
							startActivity(intent);
							CommonUtility
									.finishActivityFromName(RegisterFirstStepActivity.class
											.getSimpleName());
							CommonUtility
									.finishActivityFromName(RegisterSecondStepActivity.class
											.getSimpleName());
							CommonUtility
									.finishActivityFromName(RegisterThirdStepActivity.class
											.getSimpleName());
							CommonUtility
									.finishActivityFromName(LoginActivity.class
											.getSimpleName());
						}
					}
				});
				add(t);
			}
		});
		add(task);
	}

	@Override
	public void onBackPressed() {
	}
	
	
/*	@Override
	public void onResume() {
		super.onResume();
		MobclickAgent.onResume(getContext());
	}

	@Override
	public void onPause() {
		super.onPause();
		MobclickAgent.onPause(getContext());
	}*/
}
